<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>주문상세정보</title>
<link href="/Jangdolbaeng2/css/bootstrap.min.css" rel="stylesheet">
<link href="/Jangdolbaeng2/css/customer/common.css" rel="stylesheet">
<script src="/Jangdolbaeng2/js/jquery-1.11.1.js"></script>
<script src="/Jangdolbaeng2/js/bootstrap.min.js"></script>
<style type="text/css">
table {
	text-align: center;	 
}
</style>
<script type="text/javascript">
$(document).ready(function(){
	var sum = 0;
	$(".sum").each(function(){
		sum += parseInt($(this).html());
	});
	
	$("#total").html(sum);
	
	deliverybtn();
	
})//ready
	
function deliverybtn() {
	var result = '<s:property value="delivery.RESULT"/>';
		
	if(result != 't') {
		$('#delivery_end').html('<button type="button" class="btn btn-success" id="btn_deliveryComplete" style="width: 200px;">배송완료</button>');
		$('#btn_deliveryComplete').click(deliveryComplete);
	}
	else {
		$('#delivery_end').html('배송이 완료되었습니다.');	
	}
	
}//deliverybtn()

function deliveryComplete() {
	
	var order_seq = "<s:property value="delivery.ORDER_SEQ"/>";
	
	if(confirm('배송완료 하셨나요?')) {
		$.ajax({
			url: 'delivery_complete.action',
			type: 'POST',
			dataType: 'json',
			data: {
				order_seq: order_seq
			},
			success: function result() {
				alert('배송이 완료되었습니다.');
				location.href="orderForm.action";
			}//result()			
		});//ajax
	}//iv
}//deliveryComplete()

function prepared(product_seq) {
	
	var order_seq = ${order_seq};
	
	
	if(confirm("해당상품 준비완료 하셨나요?")){
		
		$.ajax({
			url: 'orderPrepared.action',
			type: 'POST',
			dateType: 'html',
			data: 
			{
				order_seq: order_seq,
				product_seq: product_seq
			},
			success: function (html) {
				$('#orderDetail').html(html);
			}
		});		
	}
	
}//prepared()

function notPrepared(product_seq) {
	var order_seq = ${order_seq};		
	
	
	if(confirm("미완료 상태로 돌릴까요?")){
		
		$.ajax({
			url: 'orderNotPrepared.action',
			type: 'POST',
			dateType: 'html',
			data: 
			{
				order_seq: order_seq,
				product_seq: product_seq
			},
			success: function (html) {
				$('#orderDetail').html(html);
			}
		});	
	}
	
}//prepared()



</script>
</head>
<body id="orderDetail">
<div id="header">
<%@ include file="adminHeader.jsp" %>
</div>
<div class="container">
	<div id="orderDetail" align="center">	
		<h3 align="center" style="margin-top: 50px; margin-bottom: 20px;"><span class="glyphicon glyphicon-zoom-in"></span> <span style="font-family: anew">주문상세정보</span></h3>
				
		<table class="table table-striped table-hover table-bordered">
			<tr class="success" style="font-weight: bold">
				<td>상점명</td>
				<td>상품명</td>
				<td>가격</td>
				<td>수량</td>
				<td>합계</td>
				<td>준비상태</td>
				<td style="width: 200px;">상태변경</td>
			</tr>
		<s:iterator value="order_detailList">
			<tr>		
				<td><s:property value="NAME"/></td>
				<s:url id="productDetail" action="product_detail" >
					<s:param name="product_seq" value="PRODUCT_SEQ"/>
				</s:url>
				<td><s:a href="%{productDetail}" style="color: blue;"><s:property value="PRODUCT_NAME"/></s:a></td>
				<td><s:property value="PRODUCT_PRICE"/></td>
				<td><s:property value="QUANTITY"/></td>
				<td class="sum"><s:property value="PRODUCT_PRICE * QUANTITY"/></td>
				<td><s:if test='PREP_STATUS == "f"'>미완료</s:if>
					<s:else>완료</s:else>
				</td>
				<td><div class="btn-group">
						<button type="button" class="btn btn-success" onclick="javascript:prepared('${PRODUCT_SEQ}')">준비완료</button>
						<button type="button" class="btn btn-info" onclick="javascript:notPrepared('${PRODUCT_SEQ}')">미완료</button>
					</div>
				</td>
			</tr>
			
		</s:iterator>
			<tr class="danger">
				<td style="font-weight: bold">총가격</td>
				<td></td><td style="border-right: none;"></td><td style="border-right: none;">
				<td id="total"></td>
				<td></td>
				<td></td>
			</tr>
		</table>
	</div> 
	
	<div id="delivery" align="center">
		<h3 style="margin-top: 50px; margin-bottom: 20px;"><span class="glyphicon glyphicon-road"></span> <span style="font-family: anew">배송정보</span></h3>
		<table class="table table-striped table-hover table-bordered">
			<tr>
				<td class="active" style="font-weight: bold">받으시는 분</td>
				<td><s:property value="delivery.NAME" /></td>
			</tr>
			<tr>
				<td class="active" style="font-weight: bold">휴대전화</td>
				<td><s:property value="delivery.PHONE" /></td>
			</tr>
			<tr>
				<td class="active" style="font-weight: bold">우편번호</td>
				<td><s:property value="delivery.ZIPCODE" /></td>
			</tr>
			<tr>
				<td class="active" style="font-weight: bold">주소</td>
				<td><s:property value="delivery.ADDRESS1" />
					<s:property value="delivery.ADDRESS2" />
				</td>
			</tr>
			<tr>
				<td class="active" style="font-weight: bold">배송관련 할 말</td>
				<td><s:property value="delivery.DELIVERY_COMMENT" /></td>
			</tr>
			<tr>
				<td class="active" style="font-weight: bold">장돌뱅이에게 할 말</td>
				<td><s:property value="delivery.JDB2_COMMENT" /></td>
			</tr>		
		</table>
	</div><p>
		
	<div id="delivery_end" align="center" style="margin-top: 30px; font-family: anew; font-size: 20px;">
	
	</div>
</div><!-- end of container -->
</body>
</html>